package com.roc.web.action.terminal;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

@SuppressWarnings("serial")
public class SnReleaseSearchCondition  extends BaseSearchCondition{
      
	 private String  mchtCd;
	 private String  nameBusi;
	 private String termId;
	 private String deviceCd;
 
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		//商户号
		if(Constance.isNotEmpty(mchtCd)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("TI.MCHT_CD", mchtCd.trim(), "=", false));
		}
		 
		if(Constance.isNotEmpty(nameBusi)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("MI.NAME_BUSI", nameBusi.trim(), "like", false,"ALL"));
		}
	     //终端号
		if(Constance.isNotEmpty(termId)){ 
			filedBeanList.add(new WhereHQLFieldBean("TI.TERM_ID", termId.trim(), "=", false));
		}
		//终端序列号
		if(Constance.isNotEmpty(deviceCd)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("TI.DEVICE_CD", deviceCd.trim(), "=", false));
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer  sb= new StringBuffer();		
			sb.append(" SELECT COUNT(1) "
					+ " FROM   tbl_term_inf    TI"
					+ "  LEFT JOIN tbl_mcht_inf  MI  ON  TI.MCHT_CD=MI.MCHT_CD "
					+ "  LEFT JOIN T_OPERATORS O      ON  MI.Ext1 =o.id "
					+ "   LEFT JOIN T_OPERATORS OP      ON  o.oneagentid = OP.id "
					+ "  where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer  sb= new StringBuffer();
				sb.append(" SELECT  TI.MCHT_CD,MI.NAME_BUSI,O.REAL_NAME agentName, OP.REAL_NAME oneAgentName, "
						+ "(case when TI.TERM_TP = '1' then '固定POS' else '移动POS' end) TERMTYPE ,  "
						
						+ "  TI.TERM_ID,TI.DEVICE_CD,TI.INSTALLLOCATION "
						+ "  FROM   tbl_term_inf    TI"
						+ "  LEFT JOIN tbl_mcht_inf  MI  ON  TI.MCHT_CD=MI.MCHT_CD  "
						+ "  LEFT JOIN T_OPERATORS O      ON  MI.Ext1 =o.id "
						+ "  LEFT JOIN T_OPERATORS OP      ON  o.oneagentid = OP.id "
						+ "  WHERE 1=1 ");
				     
				return sb.toString();	
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return "  ";
	}

	public String getMchtCd() {
		return mchtCd;
	}

	public void setMchtCd(String mchtCd) {
		this.mchtCd = mchtCd;
	}

	
	public String getNameBusi() {
		return nameBusi;
	}

	public void setNameBusi(String nameBusi) {
		this.nameBusi = nameBusi;
	}

	public String getTermId() {
		return termId;
	}

	public void setTermId(String termId) {
		this.termId = termId;
	}

	public String getDeviceCd() {
		return deviceCd;
	}

	public void setDeviceCd(String deviceCd) {
		this.deviceCd = deviceCd;
	}
	
	
	

}
